package com.fengwk.deeplearning.core;

import java.io.Serializable;

import org.nd4j.linalg.api.ndarray.INDArray;

import com.fengwk.support.exception.BaseException;
import com.fengwk.support.util.IoUtils;

/**
 * 样本集
 * 
 * @author fengwk
 *
 */
public class Samples implements Serializable {

	private static final long serialVersionUID = 4151616178224323572L;

	private final INDArray X;
	private final INDArray y;
	
	/**
	 * 实例化样本
	 * 
	 * @param X 样本矩阵
	 * @param y 样本结果向量行向量
	 */
	public Samples(INDArray X, INDArray y) {
		if (X.size(1) != y.size(1))
			throw new BaseException("X.size(1) != y.size(1)");
		this.X = X;
		this.y = y;
	}
	
	/**
	 * 序列化样本
	 * 
	 * @param path 保存路径
	 */
	public void serialize(String path) {
		IoUtils.write(IoUtils.objectToBytes(this), path);
	}
	
	public INDArray getX() {
		return X;
	}

	public INDArray getY() {
		return y;
	}
	
}
